package demo.ybt;

public class P1262_3 {
    public static void main(String[] args) {
        P1262_3 p1262_3= new P1262_3();
        int res = p1262_3.res(new int[]{5, 10, 20, 5, 4, 5}, new int[][]{{1, 2}, {1, 4}, {2, 4}, {3, 4}, {4, 5}, {4, 6}, {5, 6}});
        System.out.println(res);
    }
    public int res(int[] v, int[][] t) {
        int dp[] = new int[v.length + 1];

        int max = 0;
        for (int i = 0; i < v.length; i++) {
            dp[i + 1] = v[i];
            max = v[i];
        }


        for (int i = 0; i < t.length; i++) {
            //t[i]
            //dp[t[i][1]]= dp[t[i][0]] + v[t[i][1]-1];
            if (dp[t[i][0]] + v[t[i][1] - 1] > dp[t[i][1]]) {
                dp[t[i][1]] = dp[t[i][0]] + v[t[i][1] - 1];
            }
            max = Math.max(max, dp[t[i][1]]);
        }
        return max;

    }
}
